package com.hxh.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/9/10 18:32
 * Callable 接口创建线程
 */
public class Demo01 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            System.out.println(Thread.currentThread().getName() + " come in callable");
            return 1024;
        });
        // 创建一个线程
        new Thread(futureTask, "jack").start();
        // 得到返回结果
        while (!futureTask.isDone()) {
            System.out.println("wait...");
        }
        System.out.println(futureTask.get());
        System.out.println(futureTask.get());
        System.out.println(Thread.currentThread().getName() + " come over");
    }
}
